package timeCardTransaction;

import java.util.Date;

import addEmployeeTransaction.Employee;

import classification.HourlyClassification;
import database.PayrollDatabase;

import main.Transaction;

public class TimeCardTransaction extends Transaction {
	private Date date;
	private double hours;
	private int empId;

	public TimeCardTransaction(Date date, double hours, int empId,
			PayrollDatabase database) {
		super(database);
		this.date = date;
		this.hours = hours;
		this.empId = empId;
	}

	@Override
	public void execute() throws Exception {
		Employee e = database.getEmployee(empId);
		if (e != null) {
			HourlyClassification hc = (HourlyClassification) e
					.getClassification();
			if (hc != null) {
				hc.addTimeCard(new TimeCard(date, hours));
			} else {
				throw new Exception("Employee doesn't work hourly.");
			}
		} else {
			throw new Exception("No employee with this id.");
		}
	}
}
